#ifndef EMAILMANAGERSINGLETON_H
#define EMAILMANAGERSINGLETON_H

#include <QObject>
#include <QSharedPointer>
#include <QString>
#include <QUrl>
#include "smtp/qxtsmtp.h"
#include <QTime>

class EmailManagerSingleton : public QObject{
    Q_OBJECT
public:
    static EmailManagerSingleton *getInstance();
    void sendEmail(QString title, QString content, QString imageFilePath);
    void sendAutoSnappingEmail(QUrl imageFilePath);
    bool isEmailSettingsFilled();


signals:
    void connectionFailed( const QByteArray & msg );
    void authenticationFailed( const QByteArray & msg );
    void mailFailed(int mailID, int errorCode, const QByteArray & msg);

public slots:
    void sendTestEmail();

protected slots:
    void onFailed( const QByteArray & msg );
    void onMailFailed(int mailID, int errorCode, const QByteArray & msg);


    private:
    explicit EmailManagerSingleton(QObject *parent = 0);
    static QSharedPointer<EmailManagerSingleton> instance;
    void _connectSlots();
    void connectToSmtp();
    void disconnectOfSmtp();
    void reconnectToSmtp();
    QSharedPointer<QxtSmtp> smtp;
    bool smtpConnected;
    QTime lastTimeWithServer;
};

#endif // EMAILMANAGERSINGLETON_H
